package com.zelin.manager.web;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;
import com.alibaba.dubbo.config.annotation.Reference;
import com.zelin.entity.ItemCatEntity;
import com.zelin.sellergoods.service.ItemCatService;
import com.zelin.utils.PageUtils;
import com.zelin.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;




/**
 * 商品类目
 *
 * @author WF
 * @email 2568783935@qq.com
 * @date 2021-07-23 21:10:35
 */
@RestController
@RequestMapping("/itemcat")
public class ItemCatController {
    @Reference(timeout = 5000)
    private ItemCatService itemCatService;
    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = itemCatService.queryPage(params);
        return R.ok().put("page", page);
    }


    /**
     * 功能: 查询所有分类
     * 参数:
     * 返回值: com.zelin.utils.R
     * 时间: 2021/7/30 14:28
     */
    @RequestMapping("/findAll")
    public R findAll(){
        return R.ok().put("list", itemCatService.list());
    }

    @RequestMapping("/findByParentId/{pid}")
    public R findByParentId(@PathVariable Long pid){
        List<ItemCatEntity> entityList = itemCatService.findByParentId(pid);
        return R.ok().put("list",entityList);
    }
    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("manager:itemcat:info")
    public R info(@PathVariable("id") Long id){
		ItemCatEntity itemCat = itemCatService.getById(id);

        return R.ok().put("itemCat", itemCat);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("manager:itemcat:save")
    public R save(@RequestBody ItemCatEntity itemCat){
		itemCatService.save(itemCat);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("manager:itemcat:update")
    public R update(@RequestBody ItemCatEntity itemCat){
		itemCatService.updateById(itemCat);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("manager:itemcat:delete")
    public R delete(@RequestBody Long[] ids){
		itemCatService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
